
/**
 * Loads the config from config.js
 */

function loadConfig() {
    
    //my custom javascript "ini loader" so to speak. Somewhat in the spirit of the associative array returned by PHP parse_ini_file function      
    //Insight07072011 TODO/ IT watch:there may be framework/best practice out there for this problem which seems a very common scenario to me!
    currentConfigStage=CONFIG.stage;
    
    if (currentConfigStage == "standalone")
        //if we're in in a standalone page
        currentConsole=console;
    else
        //if we're in the extension container
        currentConsole=chrome.extension.getBackgroundPage().console; 
    
    
    currentConsole.log("popup.js loadConfig() : initializating ...");
    currentConsole.log("popup.js loadConfig() : MODE "+currentConfigStage);

    loadPlaceholdersElements();
    currentConsole.log("popup.js loadConfig() : placeholders loaded...");
    if (currentConfigStage=="testing") {
        testPlaceholdersLoadedOk();
 
    }        
    loadCssStylesheet();
    currentConsole.log("popup.js loadConfig() : stylesheet loaded...");

    

    if (currentConfigStage=="development") {
    
    
    
    }
    else if (currentConfigStage=="testing") {
        
    //        testLoadSinglePlaceholder();

    }
    else if (currentConfigStage=="production") {
    
}

   

    
    
}

function loadPlaceholdersElements() {
    

    $inputTags=$("."+inputTagsPlaceholder+".value");
    $inputTagsCaption=$("."+inputTagsPlaceholder+".caption");

    $inputUrl=$("."+inputUrlPlaceholder+".value");
    $inputUrlCaption=$("."+inputUrlPlaceholder+".caption");

    $inputTitle=$("."+inputTitlePlaceholder+".value");
    $inputTitleCaption=$("."+inputTitlePlaceholder+".caption");
    
    $inputTriggerFeedQuery=$("."+inputTriggerFeedQueryPlaceholder+".value");
    $inputTriggerFeedQueryCaption=$("."+inputTriggerFeedQueryPlaceholder+".caption");
    
    $outputFeedback=$("."+outputFeedbackPlaceholder+".value");
    $outputFeedbackCaption=$("."+outputFeedbackPlaceholder+".caption");
}

function loadCssStylesheet() {
         
    var link = $("<link>");
    link.attr({
        type: 'text/css',
        rel: 'stylesheet',
        href: CONFIG.css.development
    });
    $("head").append( link ); 
}

function applyCssStylesheet() {
    
}

function loadJqueryHandlers() {
    $inputTriggerFeedQuery.click(function() {
        triggersBookmarksCreateQuery();
    });
    
    $(".tag-container-close-icon").live("click",null,function() {
        var tagToRemove=$(this).parent(".tag-container").attr("tag");        
        triggersBookmarksDeleteByUrlAndTagQuery(tagToRemove);
    });
}

function loadJqueryMisc() {
    $inputTags.autocomplete({
        source: "http://localhost/markMyWeb/ajax/bookmarks.php?action=read",
        minLength: 2
    });
}